var typeStr = "";

(function(e) {

	mui.plusReady(function() {
		plus.navigator.setStatusBarBackground('#7dd5fb');
		typeStr = getQueryString("typeStr");
		getStoreList(typeStr);
	});

})(mui);

//Phone_GetStore_In_Main Phone_GetStore_Out_Main 

function getStoreList(type) {
	$("#warehouseList").html('');
	var opName = "Phone_GetStore_In_Main";
	if(type == "出库操作") {
		opName = "Phone_GetStore_Out_Main";
		$('.mui-title').html('出库列表');
	} else {
		$('.mui-title').html('入库列表');
	}

	var jsonData = {
		op: opName
	}

	if(checkParams(jsonData)) {
		mui.toast("请求失败,请稍后再试");
		return;
	}
	var opts = {
		url: "",
		addressUrl: "testline",
		requestType: "POST",
		pastDate: jsonData
	};

	console.log(JSON.stringify(opts));
	plus.nativeUI.showWaiting();
	crossDomainAjax(opts, function(data) {
		console.log(JSON.stringify(data));
		plus.nativeUI.closeWaiting();
		if(!isEmpty(data)) {
			for(var i = 0; i < data.length; i++) {
				createItem(data[i]);
			}
		} else {
			$('.mui-content').html(
				'<div class="empty-list">暂无'+
				(typeStr == '出库列表' ? '出库计划': '入库计划')+
				'</div>'
			);
		}

		$("#warehouseList li").click(function() {
			var itemId = this.id;

			var postData = {
				pageflag: "warehouseList.html",
				itemId: itemId,
				type:type
			}
			var pageChange1 = {
				pageUrl: "wearhoursInfo.html",
				createNew: true,
				postData: postData,
				aniShow: "fade-in"
			}
			pageChange(pageChange1);
		});

	});

}

function createItem(item) {
	var createLi = document.createElement("li");
	createLi.id = item.JobCode;
	typeStr = getQueryString("typeStr");
	var typeText = typeStr == '出库操作' ? '出库单号': '入库单号';
	createLi.innerHTML = '<div class="item-header"><span>'+typeText+'：</span><span>' + item.JobCode + '</span></div>' +
		'<div class="item-info"><span>货主：</span><em>' + item.UnitName + '</em><br /><span>仓库：</span><em>' + item.StoreName + '</em></div>';
	$("#warehouseList").append(createLi);
}

function refresh() {
	typeStr = getQueryString("typeStr");
	getStoreList(typeStr);
}
